#!/bin/bash
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
   echo "Updates:"
   echo "   update (--gitlab, --github) Updates Floflis DNA (centralized, yet)"
fi

if [ "$1" = "update" ] || [ "$1" = "updt" ] || [ "$1" = "next" ] || [ "$1" = "up" ]; then
   if [ "$2" = "" ]; then
      echo "Can't update yet on a decentralized manner. Please use 'update --gitlab' command."
      echo ""
      echo "Probably GitLab will ask you for login (their fault), and when updating from GitHub maybe it tells about conflicts when merging (as recently - 07-12-2019 - GitHub updates are working). When you can't update, I ask you to keep your clonned git folder of Floflis DNA, update using 'git pull' inside it, open init.sh and then manually re-install it."
      echo ""
      echo "Not a company developing Floflis. I'm Daniell W. J. Mesquita, a brazillian individual (persecuted with lawfare due to eco/social activist) developing Floflis thinking on common good. I promise I're working hard to make Floflis DNA upgradeable, and to enable P2P updates on Floflis Core."
      echo ""
      echo "Type 'floflis update --gitlab' to try update from GitLab, or 'floflis update --github' to update from GitHub."
fi
fi

if [ "$1" = "update" ]; then
   if [ "$2" = "gitlab" ] || [ "$2" = "--gitlab" ]; then
      echo "- Updating Floflis DNA (from GitLab)..."
      echo "(i) Updating a Layer requires sudo mode;"
      cd /usr/sbin/layers/dna && sudo git pull origin master
#      echo "(✓) Successfully updated Floflis DNA."
fi
   if [ "$2" = "github" ] || [ "$2" = "--github" ]; then
      echo "(?) GitHub is owned by Microsoft. Are you sure Microsoft likes us?"
      echo "1. Yes, I'll receive Floflis updates from Microsoft"
      echo "2. No"
      echo "Please type 1 or 2 according to your choice, and press [ENTER]:"
      read microsoftyes
      if [ "$microsoftyes" = "" ]; then
         echo "What?"
         floflis
fi
      if [ "$microsoftyes" = "2" ]; then
         echo "If you don't trust MS, you're a true Floflis citizen."
         floflis update
fi
      if [ "$microsoftyes" = "1" ]; then
         echo "If you receive a blue screen, don't blame on us." && echo "- Updating Floflis DNA (from Microsoft GitHub)..."
         echo "(i) Updating a Layer requires sudo mode;"
         cd /usr/sbin/layers/dna
         sudo git pull github master
fi
fi
fi
